Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the last olm session that got a message #776

Merged
merged 9 commits into from
Nov 15, 2018

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Nov 1, 2018

@dbkr
Copy link
Member Author

dbkr commented Nov 1, 2018

Tests now failing because of lack of new olm - looks like there are still issues on node 11

dbkr added a commit that referenced this pull request Nov 8, 2018
 * Start a new Olm sessions with a device when we get an undecryptable
   message on it.
 * Send a dummy message on that sessions such that the other end knows
   about it.
 * Re-send any outstanding keyshare requests for that device.

Also includes a unit test for megolm that isn't very related but came
out as a result anyway.

Includes #776
Fixes element-hq/element-web#3822
@dbkr dbkr mentioned this pull request Nov 8, 2018
@dbkr dbkr requested a review from uhoreg November 8, 2018 19:28
Copy link
Member

@uhoreg uhoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, other than a typo, a minor performance tweak, and pending the question of whether the timestamp should be stored in olm or separately

return a.sessionId < b.sessionId ? -1 : 1;
}
});
return sessionInfos[sessionInfos.length - 1].sessionId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looping through the sessionInfos array, and keeping track of the sessionId with the smallest timestamp/sessionId is approximately the same number of lines of code, and faster (O(n) rather than O(n log n)). i.e.

let idxOfMin = 0;
for (i = 1; i < sessionInfos.length; i++) {
  if (sessionInfos[i].lastReceivedMessageTs < sessionInfos[idxOfMin].lastReceiveMessageTs
      || (sessionInfos[i].lastReceivedMessageTs === sessionInfos[idxOfMin].lastReceiveMessageTs
          && sessionInfos[i].sessionId < sessinInfos[idxOfMin].sessionId)) {
    idxOfMin = i;
  }
return sessionInfos[idxOfMin].sessionId;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I was reluctant to bother changing it since it was already a sort, but fair enough

@@ -509,6 +509,8 @@ OlmDevice.prototype.createInboundSession = async function(
this._storeAccount(txn, account);

const payloadString = session.decrypt(messageType, ciphertext);
// this counts as an received message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/a/

Copy link
Member

@uhoreg uhoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm other than a couple typos

results[cursor.value.sessionId] = cursor.value.session;
results[cursor.value.sessionId] = {
session: cursor.value.session,
lastReceivedMessagets: cursor.value.lastReceivedMessageTs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the case changed here (lastReceivedMessagets vs lastReceivedmessageTs)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good spot

func(getReq.result.session);
func({
session: getReq.result.session,
lastReceivedMessagets: getReq.result.lastReceivedMessageTs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member

@uhoreg uhoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and a couple more typos

// Pretend we've received a message at this point, otherwise
// if we try to send a message to the device, it won't use
// this session (storing the creation time separately would
// make the pickle longer and would not be useful otherwise).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not stored in the pickle any more

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, yep

this._saveSession(theirDeviceIdentityKey, session, txn);
const sessionInfo = {
session,
// this counts as an received message: set last received message time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/a/

Copy link
Member Author

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ptal!

// Pretend we've received a message at this point, otherwise
// if we try to send a message to the device, it won't use
// this session (storing the creation time separately would
// make the pickle longer and would not be useful otherwise).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, yep

return a.sessionId < b.sessionId ? -1 : 1;
}
});
return sessionInfos[sessionInfos.length - 1].sessionId;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I was reluctant to bother changing it since it was already a sort, but fair enough

results[cursor.value.sessionId] = cursor.value.session;
results[cursor.value.sessionId] = {
session: cursor.value.session,
lastReceivedMessagets: cursor.value.lastReceivedMessageTs,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good spot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants